import React from 'react';
import {connect} from 'dva';
import {Button, Row, Form, Input} from 'antd';
import styles from './login.less';

const FormItem = Form.Item;

class Login extends React.Component {

  handleOk = (e) => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((errors, values) => {
      if (errors) {
        return
      } else {
        this.props.dispatch({
          type: 'mflogin/dologin',
          payload: values
        });
      }
    });
  };

  render() {
    return (
      <div id="loginclass">
        <div className={styles.form}>
          <div className={styles.logo}>
            <img alt={'logo'} src='/img/logo.png'/>
            <span>登&nbsp;&nbsp;&nbsp;&nbsp; 录 </span>
          </div>
          <form>
            <FormItem hasFeedback>
              {
                this.props.form.getFieldDecorator('username', {
                  rules: [
                    {
                      required: true,
                      message: '电话号码不能为空'
                    },
                  ],
                })(<Input size="large" onPressEnter={this.handleOk} placeholder="电话"/>)
              }
            </FormItem>
            <FormItem hasFeedback>
              {
                this.props.form.getFieldDecorator('pswd', {
                  rules: [
                    {
                      required: true,
                      message: '密码不能为空'
                    },
                  ],
                })(<Input size="large" type="password" onPressEnter={this.handleOk} placeholder="密码"/>)
              }
            </FormItem>
            <Row>
              <Button type="primary" size="large" onClick={this.handleOk}>
                登录
              </Button>
              {/*  <p>
              <span>Username：admin</span>
              <span>Password：admin</span>
            </p>*/}
            </Row>
          </form>
        </div>
      </div>
    );

  };
}

function mapStateToProps(state) {
  return {}
}

export default connect()(Form.create(mapStateToProps)(Login))
